//index.js
//获取应用实例
var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url:app.setting.att_url,
		account:app.setting.account,
		loading:true,
		pagetitle:'足迹' + '-' + app.setting.title,
		
	},
	onReady: function (){
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (){
		var page=this;
		wx.setNavigationBarTitle({'title':page.data.pagetitle});

		app.util.get(app.access,function(pagedata){
			//console.log('pagedata');console.log(pagedata);
			
			page.setData({
				pagedata:pagedata
			});
			page.get_list(1);
		});
	},
  	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util[data.func](data.params);
	},
	//翻页
	onReachBottom: function () {
		var isnodata=this.data.isnodata
		var loading=this.data.loading
		if(!isnodata && !loading){
			this.get_list()
		}
	},
	get_list:function(e){
		var the=this;
		var page = the.data.page
		var pagedata=the.data.pagedata
		if(e==1){
			page = 1;
			pagedata.list=[];
		}		
		var query='page='+page;	
		app.util.get('/member.history/getlist/'+query,function(res){
			pagedata.list = pagedata.list.concat(res.list)
			page++
			the.setData({
				'pagedata.list':pagedata.list,
				page:page,
				loading:false,
			});
		});
	},
	show_edit:function(){
		var the=this
		var pagedata = the.data.pagedata
		the.setData({
				'pagedata.show_edit':!pagedata.show_edit,
		});
	},
	selected_del:function(e){
		var the=this
		var data=e.currentTarget.dataset;
		var pagedata = the.data.pagedata
		var selected = pagedata.list[data.index].selected==1 ? 0 :1;
		pagedata.list[data.index].selected=selected;
		app.util.duoxuans(data.id,pagedata.del,function(res){
			console.log(res);
			the.setData({
				'pagedata.del':res,
				'pagedata.list':pagedata.list,
			});
		});
	},
	selectedall:function(){
		var the=this
		var pagedata=the.data.pagedata
		var selectedall = the.data.selectedall
		for (var i=0; i<pagedata.list.length; i++){
			if(!pagedata.list[i].outtype){
				pagedata.list[i].selected=selectedall?0:1;
				app.util.duoxuans(pagedata.list[i].id,pagedata.del,function(res){
					console.log(res);
					the.setData({
						'pagedata.del':res,
					});
				});
			}
		}
		the.setData({
				'pagedata.list':pagedata.list,
				selectedall:!selectedall,
		});
	},
	del:function(){
		var pagedata = this.data.pagedata
		app.util.post('/member.history/del/del='+pagedata.del,{})
	},
	formSubmit:function(event){
		var data=event.detail.value;
		app.util.post('/member.history/post/',data);
	}
});